<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/admindetails.php';
include_once '../../model/email.php';
include_once("../../model/users.php");
require_once '../../redirect.php';

checkUserLogin();

## Create Objects
/*******************************/
$adminObj = new Model_AdminDetails();
$emailObj = new  Model_Email();
$userObj = new Model_Users();
/*******************************/

checkUserLogin();

$userId = $_SESSION['getbids_id'];

$userDetArray = $userObj->getUserDetailsByUserId($userId);
$comapnyname = str_replace(" ","_",strtolower($userDetArray['companyname']));
$userDetArray['newcomapnyname'] =$comapnyname;
$smarty->assign('userDetArray',$userDetArray);

if(isset($_POST['password_btn']))
{   
	if(trim($_POST['current_pass'])!='' && trim($_POST['pass'])!='' && trim($_POST['cpass'])!='') 
	{
		if($userDetArray['password'] == md5(trim($_POST['current_pass'])))	
		{			
			$PassArray				= array();
			$PassArray['password']	= md5($_POST['pass']);
			$userObj->editUserValueById($PassArray,$userId);
			$_SESSION['msg'] = "<div class='success_msg'><span>Your password changed successfully.</span></div>";
		}
		else
		{
			$_SESSION['msg'] = "<div class='error_msg'><span>Current password not match.</span></div>";	
		}
	}
	else
	{
		$_SESSION['msg'] = "<div class='error_msg'><span>All fields are mandatory.</span></div>";				
	}
}

if($_SESSION['msg'] != ''){
	$smarty->assign("msg", $_SESSION['msg']);	
	unset($_SESSION['msg']);
}


$active = "myaccount";
$smarty->assign("active", $active);
$subactive ="changepassword";
$smarty->assign("subactive", $subactive);
$smarty->assign('mainmenu', '1');
## Unset all the objects created which are on this page
unset($userObj);

$smarty->display(TEMPLATEDIR.'/modules/myaccount/changepassword.tpl');
unset($smarty);
?>
